package com.globallogic.training.javase.university.member;

import java.util.HashSet;
import java.util.Set;


/**
 * Group of students in the university.
 * 
 * @author Artem.Zeltinsh
 */
public class Group {

	private String id;

	private Set<Student> students;

	public Group(String id) {
		this.id = id;
		this.students = new HashSet<Student>();
	}

	public String getId() {
		return id;
	}

	public boolean addStudent(Student student) {
		return students.add(student);
	}

	public boolean removeStudent(Student student) {
		return students.remove(student);
	}

	public Student getStudent(String fullName) {
		for (Student nextStudent : students) {
			if (nextStudent != null
					&& nextStudent.getFullName().equals(fullName)) {
				return nextStudent;
			}
		}

		return null;
	}
	
	public Student[] getStudents() {
		return students.toArray(new Student[students.size()]);
	}

	public int hashCode() {
		return 31 + id.hashCode();
	}
	
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Group other = (Group) obj;
		if (id.equals(other.id)) {
			return true;
		}
		return false;
	}

	public String toString() {
		return id;
	}
}
